//
//  SearchAddressCell.swift
//  GreenDeal
//
//  Created by Moennig Q on 28/2/2023.
//

import UIKit

class SearchAddressCell: UITableViewCell {
    var titleLabel: BaseLabel!
    var cellColor:UIColor?
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUpviews()
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        if selected {
            self.contentView.backgroundColor = UIColor(hexStr: "#E7F9F2")
        }else {
            self.contentView.backgroundColor = UIColor.white
            if let cellColor = self.cellColor {
                self.contentView.backgroundColor = cellColor
            }
        }
    }
    
    private func setUpviews(){
        self.selectionStyle = .none
        //model
        titleLabel = ContentLabel(R.font.interMedium(size: 15))
        titleLabel.numberOfLines = 2
        titleLabel.textAlignment = .left
        self.contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(12)
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.bottom.equalTo(-12)
            make.height.greaterThanOrEqualTo(0)
        }
    }
    func setData(_ fullAddress: String){
        self.titleLabel.text = fullAddress
    }
    
//    private func getAttributeString(content: String, subStr: String)->NSMutableAttributedString{
//        let attrString = NSMutableAttributedString(string: content)
//        let strSubAttr1: [NSMutableAttributedString.Key: Any] = [.font: R.font.interRegular(size: 15) as Any,.foregroundColor: UIColor(hexStr: "#292D32FF")]
//        let strSubAttr2: [NSMutableAttributedString.Key: Any] = [.font: R.font.interRegular(size: 15) as Any,.foregroundColor: UIColor(hexStr: "#379657FF")]
//        
//        let localtion = (content as NSString).range(of: subStr)
//        
//        attrString.addAttributes(strSubAttr1, range: NSRange(location: 0, length: content.count))
//        attrString.addAttributes(strSubAttr2, range: NSRange(location: localtion.location, length: localtion.length))
//        return attrString
//    }
    
}

